package sliver.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import sliver.dao.AdvertisementLogDao;
import sliver.entity.AdvertisementLog;

@Repository
public class AdvertisementLogDaoImpl extends BaseDaoImpl<AdvertisementLog> implements AdvertisementLogDao{
	
	@Override
	public AdvertisementLog findAdvertisementLastestLog(Serializable shopperId,
			Serializable machineId, Serializable advertisementId) {
		
		String queryString = "SELECT log " +
				             "FROM AdvertisementLog log " +
				             "WHERE log.shopper.id = ? " +
				             "AND log.machine.id = ? " +
				             "AND log.advertisement.id = ? " +
				             "ORDER BY log.showDate DESC";
		
		List<AdvertisementLog> logs = complexQuery(queryString, new Object[]{shopperId, machineId, advertisementId});
		
		if(logs != null && logs.size() > 0)
			return logs.get(0);
		
		return null;
	}
	
}
